<%= content_tag :div, class: 'add-nested-element', data: { element_id: element.id } do %>
  <% if element.nestable_elements.length == 1 &&
    (nestable_element = element.nestable_elements.first) &&
    Alchemy::Element.all_from_clipboard_for_parent_element(get_clipboard("elements"), element).none?
  %>
    <%= turbo_frame_tag("new_nested_element_#{element.id}") do %>
      <%= form_for [:admin, Alchemy::Element.new(name: nestable_element)], html: { class: 'add-nested-element-form', id: nil } do |f| %>
        <%= f.hidden_field :name %>
        <%= f.hidden_field :page_version_id, value: element.page_version_id %>
        <%= f.hidden_field :parent_element_id, value: element.id %>
        <button class="add-nestable-element-button" is="alchemy-button">
          <%= Alchemy.t(:add_nested_element, name: Alchemy.t(nestable_element.to_sym, scope: 'element_names')) %>
        </button>
      <% end %>
    <% end %>
  <% else %>
    <%= link_to_dialog (nestable_element ? Alchemy.t(:add_nested_element, name: Alchemy.t(nestable_element.to_sym, scope: 'element_names')) : Alchemy.t("New Element")),
      alchemy.new_admin_element_path(
        parent_element_id: element.id,
        page_version_id: element.page_version_id
      ), {
        size: "380x125",
        title: Alchemy.t("New Element")
      }, class: "button add-nestable-element-button" %>
  <% end %>
<% end %>
